<template>
  <div class="wrap" id="children">
    <el-dialog
      title="添加联系人"
      :visible.sync="state"
      @close="close"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form>
        <el-form-item label="输入昵称" :label-width="formLabelWidth">
          <el-input v-model="linkmanName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="输入手机号" :label-width="formLabelWidth">
          <el-input v-model="tel" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="close()">取 消</el-button>
        <el-button type="primary" @click="close(1)">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  props: {
    passworldState: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      formLabelWidth: "120px",
      linkmanName: "",
      tel: ""
    };
  },
  computed: {
    state: {
      get() {
        return this.passworldState;
      },
      set() {}
    }
  },
  methods: {
    close(v) {
      if (v) {
        if (!this.linkmanName) {
          this.$alert("请输入昵称", "提示", {
            confirmButtonText: "确定"
          });
          return false;
        }
        if (!/^1[3456789]\d{9}$/.test(this.tel)) {
          this.$alert("请输入正确的联系方式", "提示", {
            confirmButtonText: "确定"
          });
          return false;
        }
        this.$emit("getUser", { linkmanName: this.linkmanName, tel: this.tel });
      } else {
        this.$emit("getUser");
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.el-input {
  max-width: 330px;
}
.el-button {
  width: 112px;
}
.sendCode {
  display: flex;
  align-items: center;
  .el-input {
    width: auto;
    margin-right: 10px;
  }
}
</style>
<style lang="scss">
#children .el-dialog {
  width: 30% !important;
  min-width: 300px;
}
</style>